package com.ruoyi.app.controller

import com.baomidou.shaun.core.mgt.SecurityManager
import com.baomidou.shaun.core.profile.TokenProfile
import com.ruoyi.anno.NotResubmit
import com.ruoyi.app.common.Data
import com.ruoyi.app.common.Ok
import com.ruoyi.app.domain.dto.AdvertisingSettingDto
import com.ruoyi.app.domain.vo.AdvertisingSettingVo
import com.ruoyi.app.domain.vo.GlobalSetting
import com.ruoyi.app.domain.vo.IndexVo
import com.ruoyi.app.domain.vo.VideoVo
import com.ruoyi.app.service.IndexApiService
import com.ruoyi.back.domain.v3.ExtractVideo
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("api/index")
@Api(tags = ["首页相关接口"])
class IndexApiController {

    @Autowired
    private lateinit var indexApiService: IndexApiService

    @Autowired
    private lateinit var securityManager: SecurityManager

    @ApiOperation("获取首页数据")
    @GetMapping("indexData/{channelCode}")
    fun indexData(@PathVariable channelCode: String): Data<IndexVo> = indexApiService.indexData(channelCode)

    @NotResubmit(delaySeconds = 2)
    @GetMapping("test")
    @ApiOperation("测试")
    fun test() = Ok("测试成功")

    @ApiOperation("退出演示")
    @GetMapping("logoutToken")
    fun logoutToken(to: String) = securityManager.logout(TokenProfile().apply { id = to})

    @ApiOperation("获取全局参数配置")
    @GetMapping("getGlobalSetting")
    fun getGlobalSetting(): Data<GlobalSetting> = indexApiService.getGlobalSetting()


    @ApiOperation("获取广告配置参数")
    @GetMapping("getAdvertisingSetting")
    fun getAdvertisingSetting(advertisingSettingDto: AdvertisingSettingDto): Data<AdvertisingSettingVo> =
        indexApiService.getAdvertisingSetting(advertisingSettingDto)

    @ApiOperation("提取短视频")
    @GetMapping("resolveVideo")
    fun resolveVideo(@RequestParam("urlText", required = true) urlText: String): Data<List<VideoVo>> = indexApiService.resolveVideo(urlText)

    @ApiOperation("获取提取短视频体验模板")
    @GetMapping("extractVideoTemplate")
    fun extractVideoTemplate(): Data<List<ExtractVideo>> = indexApiService.extractVideoTemplate()
}